<?php
class AllAction extends Action{
    function _initialize(){
		$webid=$this->get_webid();
		$this->assign('webid', $webid);
		$webmenuid=$this->get_webmenuid();
		//网站系统配置
		$s = M('sysconfig')->where("webid=".$webid."")->order('id asc')->select();
		foreach ($s as $v) {
			$C[$v['varname']] = $v['value'];
			if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
				$C[$v['varname']] = stripslashes($v['value']);
			}
		}
		if($C['webstatus']=='0'){$this->redirect('Public/close');}
		$this->assign('C', $C);
		
		//当前完整url
		$wanzheng_url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];		
		$this->assign('wanzheng_url',$wanzheng_url);
		//var_dump($wanzheng_url);

		$all_lang=M('pz_lang')->where("state=1 and id>1")->order('xu asc,id asc')->select();
	    $this->assign('all_lang', $all_lang);
		$sz_area_id=$_COOKIE['sz_area_id'];
		$this->assign('sz_area_id',$sz_area_id);
		
		$lid=$_COOKIE['langid'];
		if($lid<1 || $lid==NULL){
			$lid=1;
		}
		$this->assign('lid',$lid);
		
		$uid=$_COOKIE['id'];
		if(!empty($uid)){
			$user_login=M('user')->find($uid);
			if($user_login['nicheng']){
				$user_login['nicheng']=$user_login['nicheng'];
			}else{
				$user_login['nicheng']=$user_login['tel'];
			}
			$this->assign('user_login',$user_login);
		}
		//网站字典配置
		$zidian = M('pz_zidian')->where("mid=0")->order("id asc")->select();
			$zidian=$this->get_lang_attr($zidian,"name");
		$this->assign('zidian',$zidian);
		
		//网站单页_文章
		$main_page_art = M('page_art')->where("state=1")->order("xu asc,stime desc,id desc")->select();
			$main_page_art=$this->get_lang_attr($main_page_art,"name");
		$this->assign('main_page_art',$main_page_art);
		
	}
	//二维 数组 获取 各字段语言 优先级别
	function get_lang_attr($attr,$data){
		if($_COOKIE["langid"]>0){
			$lid=$_COOKIE["langid"];
		}else{
			$lid=1;
		}
		foreach($attr as $k=>$v){
			$attr[$k]["".$data.""]=$v["".$data.$lid.""];
			if( empty($attr[$k]["".$data.""]) ){
				$attr[$k]["".$data.""]=$v["".$data."3"];				
				if( empty($attr[$k]["".$data.""]) ){
					$attr[$k]["".$data.""]=$v["".$data."1"];				
					if( empty($attr[$k]["".$data.""]) ){
						$attr[$k]["".$data.""]=$v["".$data.""];				
					}
				}
			}
			if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
				$attr[$k]["".$data.""]=stripslashes($attr[$k]["".$data.""]); 
			}
		}
		return $attr;
	}
	//一维 数组 获取 各字段语言 优先级别
	function get_lang($attr,$data){
		if($_COOKIE["langid"]>0){
			$lid=$_COOKIE["langid"];
		}else{
			$lid=1;
		}
		$beifen_attr_data=$attr["".$data.""];
		$attr["".$data.""]=$attr["".$data.$lid.""];
		if( empty($attr["".$data.""]) ){
			$attr["".$data.""]=$attr["".$data."3"];				
			if( empty($attr["".$data.""]) ){
				$attr["".$data.""]=$attr["".$data."1"];				
				if( empty($attr["".$data.""]) ){
					$attr["".$data.""]=$beifen_attr_data;				
				}
			}
		}
		foreach($attr as $k=>$v){
			if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
				$attr[$k]=stripslashes($v); 
			}
		}
		return $attr;
	}
	//获取缩略图thumb
	function get_thumb($data){
		
		$thumb_array=explode("/",$data);
		$num=count($thumb_array)-1;
		
		$i=0;
		for($i;$i<$num;$i++){
			$thumb_str.=$thumb_array[$i]."/";
		}
		
		$thumb="./".$thumb_str."/thumb/".$thumb_array[$num]; //得到缩略图地址
		$thumb=str_replace('//','/',$thumb);
		//判断缩略图是否存在
		$pan=is_file($thumb);
		if($pan){
			return $thumb;
		}else{
			return $data;
		}
	}
	//获取缩略图thumb2
	function get_thumb2($data){
		
		$thumb_array=explode("/",$data);
		$num=count($thumb_array)-1;
		
		$i=0;
		for($i;$i<$num;$i++){
			$thumb_str.=$thumb_array[$i]."/";
		}
		
		$thumb="./".$thumb_str."/thumb2/".$thumb_array[$num]; //得到缩略图地址
		$thumb=str_replace('//','/',$thumb);
		//判断缩略图是否存在
		$pan=is_file($thumb);
		if($pan){
			return $thumb;
		}else{
			return $data;
		}
	}
	//获取缩略图thumb3
	function get_thumb3($data){
		
		$thumb_array=explode("/",$data);
		$num=count($thumb_array)-1;
		
		$i=0;
		for($i;$i<$num;$i++){
			$thumb_str.=$thumb_array[$i]."/";
		}
		
		$thumb="./".$thumb_str."/thumb3/".$thumb_array[$num]; //得到缩略图地址
		$thumb=str_replace('//','/',$thumb);
		//判断缩略图是否存在
		$pan=is_file($thumb);
		if($pan){
			return $thumb;
		}else{
			return $data;
		}
	}
	//获取当前网址对应的id
	function get_webid(){
		$wangzhi=$_SERVER['HTTP_HOST'];
		$webs=M('webs')->where("website='".$wangzhi."' and state=1")->find();
		return $webs['id'];
	}
	//获取当前网址对应的pz_menu_id
	function get_webmenuid(){
		$wangzhi=$_SERVER['HTTP_HOST'];
		$webs=M('webs')->where("website='".$wangzhi."' and state=1")->find();
		return $webs['menuid'];
	}
	
	
}
?>